Configuring Ports for Cluster environment

  1. Change the port numbers, for each instance, in each instance to avoid conflicts while running the servers. The port numbers can be changed in <tomee home dir>/conf/server.xml file.
    server.xml for cluster

    <Server port="1005" shutdown="SHUTDOWN">
    <!-- TomEE plugin for Tomcat-->
    <Listener className="org.apache.tomee.catalina.ServerListener" />
    <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
    <!-- Security listener. Documentation at /docs/config/listeners.html
    <Listener className="org.apache.catalina.security.SecurityListener" />
    -->
     
    <Connector port="1010" protocol="HTTP/1.1"
    connectionTimeout="20000"
    redirectPort="8449" xpoweredBy="false" server="Apache Tomcat" />
     
    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector protocol="AJP/1.3" port="8009" redirectPort="8443" />
  2. The catalina.properties file in the conf folder needs to be modified so as to make the TomEE container to pick custom configuration or jars defined by user.

Encrypting Passwords in Tomcat

Its a good practice to encrypt the data base passwords in server.xml and user passwords in tomcat-users.xml. Following is sample procedure/steps to encrypt the corresponding passwords.

Note: The following configuration is just an example to hash the passwords using 'SHA-512' algorithm. This should be changed depending upon the standards prescribed by individual companies.

To Hash the data base password in Tomcat_user.xml or other place

  1. Navigate to the bin folder in Tomcat home directory.

  2. Depending on the OS, open the corresponding files

    1. Run the digest script ./digest.sh -a sha-256 "MyPlainTextPassword" for linux and digest.bat -a sha-256 "MyPlainTextPassword" for windows

    2. Type the following:

      1. Once the hashed string is available, update the password in the %catalina_home%/conf/host/app-context.xml file as below: Sample Configuration

        <Resource id="ADMINSERVERSEARCHDS" type="javax.sql.DataSource">
        jdbcDriver = oracle.jdbc.driver.OracleDriver
                       jdbcUrl = jdbc:oracle:thin:@localhost:1521:orcl
                       userName = oipaqa
                       password = pfgn0gS/5rozVUv5LG7YLA==
                       PasswordCipher = Static3DES
                       jtaManaged = false
        
        </Resource>

To Hash the user password in tomcat-users.xml

  1. Navigate to the bin folder in Tomcat home directory.

  2. Depending on the OS, open the corresponding files

    1. Open digest.bat for Windows. Open digest.sh for Linux

  3. Generate the hashed string for the user password by providing the user password as input.

    1. For Using the SHA-256 algorithm:

      1. ./digest.sh -a sha-256 -h org.apache.catalina.realm.MessageDigestCredentialHandler password (this password is the actual user password) → For Linux env.

      2. digest.bat -a sha-256 -h org.apache.catalina.realm.MessageDigestCredentialHandler password (this password is the actual user password) → For Windows env.

    2. For Using the SHA-512 algorithm:

      1. ./digest.sh -a sha-512 -h org.apache.catalina.realm.MessageDigestCredentialHandler password (this password is the actual user password) → For Linux env.

      2. digest.bat -a sha-512 -h org.apache.catalina.realm.MessageDigestCredentialHandler password (this password is the actual user password) → For Windows env.

    3. For Using the SHA-md5 algorithm:

      1. ./digest.sh -a md5 -h org.apache.catalina.realm.MessageDigestCredentialHandler password (this password is the actual user password) → For Linux env.

      2. digest.bat -a md5 -h org.apache.catalina.realm.MessageDigestCredentialHandler password (this password is the actual user password) → For Windows env.

  4. Once the hashed string is generated with any of the above algorithms, change the configurations in server.xml file
    Configuration

<Realm className="org.apache.catalina.realm.LockOutRealm">
<!-- This Realm uses the UserDatabase configured in the global JNDIresources under the key "UserDatabase". Any editsthat are performed against this UserDatabase are immediatelyavailable for use by the Realm. ¿
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase">
<CredentialHandler className="org.apache.catalina.realm.MessageDigestCredentialHandler" algorithm="SHA-512" />
</Realm>
</Realm>

The algorithm which selected for hashing the given password should the same as the algorithm mentioned in the server.xml file.
5. Finally, the generated hashed password should be updated in the tomcat-users.xml file.

Example

<user username="<UserName>" password="c732f45c5877232dbbc992b464f381019c16c4b7bb8680a1452a08f6db6d910f$1$c1daf3eb0daadcb0e60ca97f42048c17143c7487b29ced0deb18994b856737a0f8274e40a121eca99ff0ff0579b8fcc413310ace9cb0fce543beeb4d462d5801" roles="<RoleName>" />